package leetcodecompetition.D367;

/**
 * @Author: Siantar
 * @Date: 2023-10-15-11:41
 * @Description: 1.0
 */
public class T8026 {
    public int[][] constructProductMatrix(int[][] grid) {
        int s = 0;
        int M = 12345;
        int n = grid.length, m = grid[0].length;
        int[][] left = new int[n][m];
        int[][] res = new int[n][m];
        for (int i = n - 1; i >= 0; i--) {
            for (int j = m - 1; j >= 0; j--) {
                left[i][j] = s;
                System.out.println(s);
                s = (s * (grid[i][j] % M)) % M;
            }
        }
        s = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                int r = (s * left[i][j]) % M;
                res[i][j] = r;
                s = (s * (grid[i][j] % M)) % M;
            }
        }
        return res;
    }
}
